<script type="text/javascript" src="js/updLower.js"></script>
<script type="text/javascript" src="js/ui/CreateTempImg.js"></script>
<link type="text/css" rel="stylesheet" href="css/alliance_f.css" />
<link rel="stylesheet" type="text/css" href="css/distri.css"/>
<link rel="stylesheet" type="text/css" href="css/jump.css"/>
<script type="text/javascript" src="js/jquery.getareas.js"></script>
<div class="r_content">
	<h3 class="mc_title">
		<span class="mctit_1"><span class="mctit_2">配置利润比</span></span>
    </h3>
	<form action="call/jh_alliance.php" method="post" target="ifr">
	<div class="degcon">
        <input type="hidden" name="uid" value="<?=$a_info['id']?>" />
        <input type="hidden" name="action" value="modify"/>
        <p><b>联盟名称：</b><span><input type="text" class="inptxt wid270"  name="aname" value="<?=$a_info['dtitle']?>" /></span></p>
        <p>
			<b>利润比例：</b>
			<span>
				<i>盟主</i><input type="text" id="input1" class="inptxt wid50" name="profit_a" value="<?=$a_info['ratio_a']?>" /><i>%</i>
				<i>代理商</i><input type="text" id="input2" class="inptxt wid50" name="profit_b" value="<?=$a_info['ratio_b']?>" /><i>%</i>
				<i>邀请人</i><input type="text" id="input3" class="inptxt wid50" name="profit_c" value="<?=$a_info['ratio_c']?>" /><i>%</i>
			</span>
		</p>
        <!-- <h4>（盟主：代理商：邀请人）</h4> -->
        
        <p><b>分销默认结算价</b></p>
		<a class="newprice ui-button ui-button-sorange">添加</a>
       <!--  <button type="button" class="newprice ui-button ui-button-sorange">添加</button> -->
        <h3><span class="tl_x">结算价模板</span><span class="tl_z">结算价计算方式</span><span class="tips">
                            <img class="imgie6" align="absmiddle" src="http://www.16u.cc/images/q.png" alt="角色所得=佣金*价格折扣率（百分比）* 角色佣金利润分配比率" title="角色所得=佣金*价格折扣率（百分比）* 角色佣金利润分配比率"/>
                        </span><span class="tl_f">差价</span><span class="tl_g">操作</span></h3>
        <?foreach($a_info['dprice_arr'] as $dprice):?> 
        <p>
            <input type="hidden" name="d_keys[]" value="<?=$dprice['k']?>"/>
            <b><input type="text" name="d_name[]" value="<?=$dprice['name']?>" class="inptxt wid80"/></b>
            <span class="tl">
                <select  style="width:100px;height:31px;background-color: #f5f5f5;border: 1px solid #e5e5e5;" name="money_g" id="money">
                    <option value="0">佣金比例</option>
                </select>
            </span>
            <input type="text" class="inptxt wid80"  name="d_price[]" value="<?=$dprice['num']?>" />
            <a href="javascript:"  data-rid="{k}" class="del" data="<?=$dprice['k']?>">删除</a>
			
        </p>
		
        <?endforeach;?>
        <p><input type="submit" class="l_save_f" onclick="add()" value="保存"  /></p>
        
	</div>
	
    </form>
<iframe name="ifr" style="display:none;"></iframe>
<script type="text/javascript">
$(document).ready(function(){
    $(".ui-select").change(function(){
        index = $(".ui-select").index($(this));
        $(".ui-select").eq(index+1).show();
    });
});;


 var inc = -1,key_index = $("input#key_index").length ? parseInt($("input#key_index").val()) :2;
    $(".del").live('click',function(){
        _this = $(this);
        if($(this).attr("data")){
            $.getJSON("call/jh_alliance.php",{keys:$(this).attr("data"),action:"queryTms"},function(data){
                if(data.code==101){
				showBg()
                    //alert("当前模板有"+data.count+"成员在使用");
                }else{
                    _this.parents("p").remove();
                }
            });
            return false;
        }
        
    });
    $(".newprice").bind('click',function(){
        if(key_index>8) {
            alert('超出！');
            return;
        }
        var content = $("#sprice").html();
        var newcontent = content.replace(/{k}/g,inc).replace(/{inc}/g,key_index);
        $(".degcon").append(newcontent);
        inc -= 1; 
        key_index += 1;
    });
</script>
<script type="text/template" id="sprice">
    <tr id="sprice_{k}">
        <td>
			<p><b><input type="text" name="d_name[]" value="" class="inptxt wid80"/></b>
				<span class="tl">
					<select  style="width:100px;height:31px;background-color: #f5f5f5;border: 1px solid #e5e5e5;" name="money_g" id="money">
						<option value="0">佣金比例</option>
						<option value="1">佣金比例</option>
						<option value="2">佣金比例</option>
					</select>
				</span>
				<input type="text" class="inptxt wid80"  name="d_price[]" value="" />
				<a href="javascript:"  data-rid="{k}" class="del" data="0">删除</a>
				
			</p>
		</td>
    </tr>
</script>
<iframe name="ifr" style="display:none;"></iframe>
<script type="text/javascript">
$(document).ready(function(){
    // $(".ui-select").change(function(){
        // index = $(".ui-select").index($(this));
        // $(".ui-select").eq(index+1).show();
    // });

    
    $(".province").change(function(){
        _this = $(this);
        flag = false;
        $(".selected").each(function(){
            if($(this).attr("data")==_this.val()) flag = true;
            
        });
        if(flag) return false;
        $.getJSON('call/jh_alliance.php',{action:'getProvince',keys:$(this).val()},function(data){
            _ds = data.key;
            _html = '<li class="itemLi odd selected" data="'+_ds+'">';
            _html +='<ul class="topUl">';
            _html +='<li class="tcol_1 tcol">'+data.title+'</li>';
            _html +='<li class="tcol_2 tcol">';
            _html +='';
            _html +='</li>';
            _html +='</ul>';
            _html +='<div class="botW clearfix">';
            _html +='<table class="table">';
            _html +='<thead>'
            _html +='<tr>';
            _html +='<th class="tbcol tbcol_1">地点</th>';
            _html +='<th class="tbcol tbcol_2">代理商账号</th>';
            _html +='</tr>';
            _html +='</thead>';
            _html +='<tbody>';
            
            for(var i in data.city){
                // alert(data.city[i].code);
                //console.log(data.city[i].ctitle);
                _html +='<tr>';
                _html +='<input type="hidden" name="city_code[]" value="'+data.city[i].code+'"/>';
                _html +='<td class="tname tbcol_1">'+data.city[i].ctitle+'</td>';
                _html +='<td data="'+_ds+'" class="agent_se" agent="'+data.city[i].inviter+'">';
                _html +=$("#hideSetion").html();
                _html +='</td>';
                _html +='</tr>';
            }
            _html +='</tbody>';
            _html +='</table>';
           // _html +='<a href="#" class="slideUpBtn"><i class="i">︽</i>收起</a>';
            _html +='</div>';
            _html +='</li>';
			_html +='<li><input type="submit" class="d_save" value="保存"></li>';
             $(".listWrap").html(_html);
             $(".list-agent").hide();
            //$(".listWrap").append(_html);
            $(".agent_se").each(function(idx,element){
                if($(this).attr("data")==_ds && $(this).attr("agent")){
                    $(this).find(".agents").val(Number($(this).attr("agent")));
                }
            });
        });
    });
});;
</script>
<div style="display:none;" id="hideSetion">
<?=$select1;?>
</div>
<form action="call/jh_alliance.php" method="post" target="ifr">
<input type="hidden" name="action" value="setAgent"/>
<h3 class="mc_title">
    <span class="mctit_1"><span class="mctit_2">指定代理商</span></span>
</h3>
<div class="ui-c-box">
    <p class="ui-line">
        <span class="ui-title">添加代理商配置：</span>        
        <span >
            <select class="ui-select province">
                <option>请选择代理省份</option>
                <?foreach($areaCode as $k => $province):?>
                <option value="<?=$k?>"><?=$province['title']?></option>
                <?endforeach;?>
            </select>
        </span>
		</br>
		<span class="ui-title">已配置的代理商：</span>
		<div class="listWrap">
        <ul id="mlistUl" class="listUl">
           
            <li><input type="submit" class="d_save" value="保存"></li>
        </ul>
    </p>
    <style type="text/css">
    .ui-t-list{border:1px solid #ccc;margin:10px 0;width:725px;}
    .ui-t-list tr:hover{background:#F7F7D1;}
    .ui-t-list .head,.ui-t-list .head:hover{font-weight:normal;color:#000;background:#e5e5e5;}
    .ui-t-list td.w1,td.w2{width:10%;white-space:nowrap;word-break:keep-all;font-weight:bold;}
    .ui-t-list td.w2{color:#FFF;background:#254E75;}
    .ui-t-list td{padding:5px 10px;vertical-align:top;vertical-align:middle;font-size:14px;text-align: center;}
    .ui-t-list a{color:#519CEA;}
    .ui-t-list a:hover{text-decoration:underline;}
    </style>
    <?if(count($exiagent)):?>
    <div class="list-agent">
    <table class="ui-t-list" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr class="head"><td >代理市</td><td>代理商</td><td>指定时间</td><td>操作</td></tr>
        <?foreach($exiagent as $at):?>
        <tr><td class="w1"><?=$at['darea_title']?></td><td><?=$at['dname']?></td><td><?=$at['dtime']?></td><td><a href="#">删除</a></td></tr>
        <?endforeach;?>
    </tbody>
    </table>
    </div>
    <?endif;?>
    
</div>
</form>

<h3 class="mc_title">
    <!-- <a href="javascript:void(0);" target="_blank">联盟管理</a> -->
    <a href="distributor_add.html" target="_blank" class="ui-t-add">添加分销商</a>
    <span class="mctit_1"><span class="mctit_2">联盟成员管理</span></span>
</h3>
<form method="post" action="call/jh_alliance.php" target="ifr" class="members">
<input type="hidden" value="buiMembers" name="action" class="mAct"/>
<?foreach($a_info['dprice_arr'] as $k=>$dprice):?>
<input type="hidden" class="keTms" value="<?=$dprice['k']?>" data="<?=$dprice['num']?>"/>
<?endforeach;?>
<table class="dismtab_a">
    <thead>
        <tr>
			<th></th>
            <th>企业名称（账号）</th>
            <th>联系人</th>
            <th>手机号码</th>
            <th>价格模板</th>
			<th>%</th>
			<th>状态</th>
        </tr>
    </thead>
    <tbody>
        <?foreach($disList as $k=>$dt):?>
        <tr>
			<td><input type="checkbox" name="memberID[<?=$dt['id']?>]" <?=$checked?> value="<?=$dt['id']?>" class="tids" /></td>
            <td style="text-align:left;padding-left:10px;"><a target="_blank" href="http://www.12301.cc/userinfo.html?id=<?=$dt['id']?>"><?=$dt['dname']?>（ID:<?=$dt['account']?>）</a></td>
            <td class="txtlf"><?=$dt['cname']?></td>
            <td><?=$dt['mobile']?></td>
            <td>
                <select name="dprice_zk[<?=$dt['id']?>]" class="dprice_tpl">
                    <option value="">请选择</option>
                    <?foreach($a_info['dprice_arr'] as $k=>$dprice):?>
                    <?$tms[$dprice['k']]=$dprice;?>
                    <option value="<?=$dprice['k']?>" <?if($dprice['k']==$dt['tm'])echo 'selected="selected"';?>><?=$dprice['name']?></option>
                    <?endforeach;?>
                </select>
            </td>
			<td>
				<input type="hidden" value="<?=$dt['tm']?>" name="dprice_tm[<?=$dt['id']?>]" class=" dprice_t"/>
				<input type="hidden" value="<?=$dt['dprice_zk']?>" name="dprice_zk[<?=$dt['id']?>]" class=" dprice_z"/>
                <span class="dprice_a"><?=$dt['dprice_zk']?></span>
			</td>
            <td>
                <? 
                echo ($dt['dstatus']==0 && $dt['dstatus']!='') ? 
                '<span style="color:green;">已配置</span>':'<span style="color:red;">未配置</span>';
                ?>
			</td>
        </tr>
        <?endforeach;?>
    </tbody>
</table>
<div class="chose">
	 <a href="javascript:void(0);" class="ckall">全选</a> 
	 <a href="javascript:void(0);" class="reck">反选</a> 
</div>
<input type="submit" class="s_save" value="加入联盟">
<a href="javascript:void(0);" onclick="join_off()">剔除</a>
</div>





<div id="dialog_a">
    <p class="close">
        <a href="#" onclick="closeBg_a();">关闭</a>
    <div>
		
    </div>
    </div>
</div>
<script>
$(document).ready(function(){
    $(".dprice_tpl").change(function(){
        var se = $(this).val();
        $(".keTms").each(function(i,e){
            if($(e).val()==se) se = $(e).attr("data");
        });
        $(this).parent().siblings().find(".dprice_t").val($(this).val());
        $(this).parent().siblings().find(".dprice_z").val(se);
        $(this).parent().siblings().find(".dprice_a").html(se);
    });
    $(".s_save").click(function(){
        $(".mAct").val("buiMembers");
    });
});
function add(){
	var value1=document.getElementById('input1').value;
	var value2=document.getElementById('input2').value;
	var value3=document.getElementById('input3').value;
	var i=new Number(value1);
	var j=new Number(value2);
	var k=new Number(value3);
	var sum=i+j+k;
	if((sum+"") == 'NaN'){
        alert("输入错误");
        return false;
	}
	else{
	if(sum!=100){
        alert("数值必须等于100");
        return false;
	}
	
}
}

function join_off(){

    if(confirm('确定要退出联盟？')){
        $(".mAct").val("outMember");
        $(".members").submit();
    }
}
function join(){
    if(confirm('确定要加入联盟？')){
        $.getJSON("call/###.php", { dtype:dtype, id:id}, function(json){
            if(json['status']!='ok'){alert(json['msg']);}
            else{alert('加入成功!');window.location.reload();}
        });
    }
}
function showBg() { 
			var bh = $("html").height();
			var bw = $("html").width(); 
			$("#fullbg").css({ 
				height:bh, 
				width:bw, 
				display:"block" 
			}); 
			$("#dialog").show(); 
		} 
		function closeBg() { 
			$("#fullbg,#dialog").hide(); 
		} 
function alliance() { 
			var bh = $("html").height();
			var bw = $("html").width(); 
			$("#fullbg").css({ 
				height:bh, 
				width:bw, 
				display:"block" 
			}); 
			$("#dialog_a").show(); 
		} 
		function closeBg_a() { 
			$("#fullbg,#dialog_a").hide(); 
		} 


$(document).ready(function(){
    $(".ckall").click(function(){ // 全选
        $(".tids").attr("checked",true).parent();
    });
    $(".reck").click(function(){// 反选
        $(".tids").each(function(index,element){
            $(this).attr("checked",!this.checked).parent();
        });
    });
    $(".add").click(function(){
        var cs = 0;
        $(".pri").each(function(index,element){
            if(!element.disabled){
                cs = Number($(this).val());
                if(cs==0) cs = Number($(".gpri").eq(index).html());
                cs = cs + 1;
                $(this).val(cs);
            }
            
        });
    });
 });
</script>
<!-- <div id="fullbg"></div> -->
<div id="dialog">
    <p class="close">
        <a href="#" onclick="closeBg();">关闭</a>
    <div>
        <div class="member_login_a">
            <div class="login_con">
                <form method="post" action="#" id="myform" name="myform">
                    
                        <h3>抱歉，您所删除的价格模板已有<?=$dprice['k']?>个用户配置</h3>
                        <h3>请转移至以下模板</h3>
                        <div class="configure"> 
							<input type="hidden" name="d_keys[]" value="<?=$dprice['k']?>"/>
							<select name="dprice_zk[<?=$dt['id']?>]" class="dprice_tpl">
								<option value="">请选择</option>
								<?foreach($a_info['dprice_arr'] as $k=>$dprice):?>
								<?$tms[$dprice['k']]=$dprice;?>
								<option value="<?=$dprice['k']?>" <?if($dprice['k']==$dt['tm'])echo 'selected="selected"';?>><?=$dprice['name']?></option>
								<?endforeach;?>
							</select>
                        </div>
						<div class="btn_con">
							<input type="submit" name="dosubmit" id="dosubmit" value="确定转移" class="reg_btn">
						</div> 
                </form> 
            </div>
        </div>
    </div>
</div>